﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace DDD.Domain.Abstract.BoxMessages
{
    internal sealed class BoxMessageConfiguration : IEntityTypeConfiguration<BoxMessage>
    {
        public void Configure(EntityTypeBuilder<BoxMessage> builder)
        {
            builder.ToTable(nameof(BoxMessage));

            builder.HasKey(x => x.Id);
            builder.Property(x => x.Id).HasComment("主键").IsRequired().ValueGeneratedNever();

            builder.Property(c => c.Name).IsRequired(true).HasComment("消息类型").HasMaxLength(100);
            builder.HasIndex(x => x.Name);

            builder.Property(c => c.Content).IsRequired().HasComment("消息主体");

            builder.Property(c => c.CreateTime).IsRequired().HasComment("创建时间").HasDefaultValue(DateTime.Now);
            builder.HasIndex(c => c.CreateTime);

            builder.Property(c => c.RetryTime).IsRequired().HasComment("重试次数").HasDefaultValue(0);

            builder.Property(c => c.LastSendTime).IsRequired(false).HasComment("上次发送时间");
        }
    }
}
